package com.top.mall.main.order

import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentStatePagerAdapter
import com.blankj.utilcode.util.BarUtils
import com.module.lemlin.owner.OwnerViewModeFragment
import com.top.mall.R
import com.top.mall.jetpack.vm.OrderViewModel
import kotlinx.android.synthetic.main.fragment_main_order.*

class OrderFragment : OwnerViewModeFragment<OrderViewModel>() {

    companion object {
        fun newInstance(): OrderFragment {
            return OrderFragment()
        }

        private val statusTabs: MutableList<String> = mutableListOf(
            "全部订单", "待付款", "待发货", "待收货", "已完成"
        )
    }

    override val layoutResId: Int
        get() = R.layout.fragment_main_order

    override fun viewModel(): OrderViewModel {
        return createViewModel()
    }

    override fun stateBar(): StatusBar {
        return StatusBar(view = flOrderBar)
    }

    override fun initView() {
        //为Toolbar添加状态栏高度
        BarUtils.addMarginTopEqualStatusBarHeight(flOrderBar)

        //tab&vp
        tlOrderStatus.setupWithViewPager(vpOrderBody.apply {
            adapter = object : FragmentStatePagerAdapter(
                childFragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
            ) {

                override fun getItem(position: Int): Fragment =
                    OrderGroupFragment.newInstance(position)

                override fun getCount(): Int = statusTabs.size

                override fun getPageTitle(position: Int): CharSequence? {
                    return statusTabs[position]
                }

                override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {}
            }
        })

        //搜索
        ivOrderSearch.setOnClickListener {

        }
    }

    override fun initData() {

    }

}